-
-
Notifications
You must be signed in to change notification settings - Fork 496
test: add tests for Vue 2 #3351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
We should probably handle this in vue 2.7 types, I need to confirm this with team. |
|
Here is my temp solution: // file: shims-vue.ts
import type { IfAny } from 'vue/types/common.js';
// components.d.ts
declare module 'vue' {
/**
* @internal
* @deprecated ⚠️,do not import this
*/
export const Transition: new () => { $props: any };
/**
* @internal
* @deprecated
*/
export type VNodeProps = {
key?: string | number | symbol;
ref?: any;
ref_for?: boolean;
ref_key?: string;
onVnodeBeforeMount?: any;
onVnodeMounted?: any;
onVnodeBeforeUpdate?: any;
onVnodeUpdated?: any;
onVnodeBeforeUnmount?: any;
onVnodeUnmounted?: any;
};
/**
* @internal
* @deprecated
*/
export type AllowedComponentProps = {
class?: unknown;
style?: unknown;
};
}
export type Slot<T extends any = any> = (...args: IfAny<T, any[], [T] | (T extends undefined ? [] : never)>) => any;
type InternalSlots = {
[name: string]: Slot | undefined;
};
export type Slots = Readonly<InternalSlots>;
declare const SlotSymbol: unique symbol;
export type SlotsType<T extends Record<string, any> = Record<string, any>> = {
[SlotSymbol]?: T;
};
type StrictUnwrapSlotsType<S extends SlotsType, T = NonNullable<S[typeof SlotSymbol]>> = [keyof S] extends [never]
? Slots
: Readonly<T>;
declare function defineSlots<S extends Record<string, any> = Record<string, any>>(): StrictUnwrapSlotsType<
SlotsType<S>
>;
type _defineSlots = typeof defineSlots;
declare global {
const defineSlots: _defineSlots;
}
import { useSlots } from 'vue';
(globalThis as any).defineSlots = useSlots;We may need to add this to vue 2.7 |
|
I'd be very happy to have that fixed in vue types if that's reasonable to expect. I wasn't sure if bigger changes like that would still be considered for Vue 2.7. |
|
cc @sodatea |
|
And BTW. Your code made me realize that this should also be handled for other Vue attributes like |
|
We'll be updating the types for Vue 2.7, but I think this PR can be kept to add tests. |
|
Reverted the change and left the test but this will obviously keep failing until Vue 2 types are updated. |
|
@xiaoxiangmoe @sodatea Can I track the progress of fixing this in Vue core somewhere? Is there an existing issue for it or should one be created? |
52d7be2 to
a61bad7
Compare
|
This branch has conflicts that must be resolved. Let me handle it. |
4ae6123 to
714b54f
Compare
7e2311f to
346b30d
Compare
346b30d to
d85bb34
Compare
|
I'll do a more thorough refactoring for vue-tsc test, but let's merge this first. Thanks! |
| <script lang="ts"> | ||
| import { defineComponent } from 'vue'; | ||
|
|
||
| const Foo = defineComponent({ | ||
| props: { | ||
| foo: String | ||
| } | ||
| }); | ||
| </script> | ||
| <script setup lang="ts"> | ||
| </script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this is a bit different from how I wrote this in my changes. My version only had one script setup block.
In Vue 3.x the
DefineComponenttypes seems to by default mergeclassandstyleprops fromAllowedComponentPropsinto the resulting component. It was added in vuejs/core#1614.In Vue 2.7 the
DefineComponentdoesn't have that logic (https://github.com/vuejs/vue/blob/49b6bd4264c25ea41408f066a1835f38bf6fe9f1/types/v3-define-component.d.ts) so we probably have to fix it on volar side.Fix by merging
JSX.IntrinsicAttributeswith component props whenstrictTemplatesis enabled and on Vue 2.7.There are also other similar places below in
__VLS_asFunctionalComponentthat checkstrictTemplatesoption but I wasn't sure in which cases those are used so haven't touched them. If you could help me figuring out testcases that would trigger those then I could update those too.BTW. Added
vue-test-workspace-vue-2folder that includes fixtures that use Vue 2.7 as only Vue 3.x was tested before. Mostly copied code fromvue-test-workspaceand added newunknownProp/main.vuetest.